package com.cmower.mkyong.immutablelist;

import com.google.common.collect.ImmutableList;

import java.io.Serializable;
import java.util.*;

/**
 * @author 沉默王二，一枚有趣的程序员
 */
public class ImmutableListDemo {
    public static void main(String[] args) {


//List<String> list = new ArrayList<>(Arrays.asList("沉默王二", "沉默王三", "沉默王四"));
//List<String> unmodifiableList = Collections.unmodifiableList(list);
//        unmodifiableList.add("沉默王五");

//final List<String> unmodifiableList = List.of("沉默王二", "沉默王三", "沉默王四");
//unmodifiableList.add("沉默王五");

//        ImmutableList list = null;
//List<String> list = new ArrayList<>(Arrays.asList("沉默王二", "沉默王三", "沉默王四"));
//List<String> unmodifiableList = ImmutableList.copyOf(list);
//unmodifiableList.add("沉默王五");

//        List<String> unmodifiableList = ImmutableList.of("沉默王二", "沉默王三", "沉默王四");

//ImmutableList<String> iList = ImmutableList.<String>builder()
//        .add("沉默王二", "沉默王三", "沉默王四")
//        .build();

//List<String> list = List.of("沉默王二", "沉默王三", "沉默王四");
////ImmutableList<String> iList = ImmutableList.<String>builder()
////        .addAll(list)
////        .build();

//List<String> list = List.of("沉默王二", "沉默王三", "沉默王四");
//ImmutableList<String> iList = ImmutableList.<String>builder()
//        .addAll(list)
//        .add("沉默王五")
//        .build();

//List<String> list = new ArrayList<>();
//list.add("沉默王二");
//
//List<String> iList = Collections.unmodifiableList(list);
//
//list.add("沉默王三");
//list.add("沉默王四");
//
//System.out.println(iList);

List<String> list = new ArrayList<>();
list.add("沉默王二");

ImmutableList<String> iList = ImmutableList.copyOf(list);

list.add("沉默王三");
list.add("沉默王四");

System.out.println(iList);

    }
}

